package com.akk.module.yb.model;

import com.akk.PayConstants;
import com.akk.module.yb.utils.Digest;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

import java.util.ArrayList;
import java.util.List;

public class TradeInfoQueryRequest {

    private String mainCustomerNumber;
    private String splitterType;
    private String customerNumber;
    private String orderNo;
    private String beginDate;
    private String endDate;
    private String pageNo;
    private String hmac;

    public String getMainCustomerNumber() {
        return mainCustomerNumber;
    }

    public void setMainCustomerNumber(String mainCustomerNumber) {
        this.mainCustomerNumber = mainCustomerNumber;
    }

    public String getSplitterType() {
        return splitterType;
    }

    public void setSplitterType(String splitterType) {
        this.splitterType = splitterType;
    }

    public String getCustomerNumber() {
        return customerNumber;
    }

    public void setCustomerNumber(String customerNumber) {
        this.customerNumber = customerNumber;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getBeginDate() {
        return beginDate;
    }

    public void setBeginDate(String beginDate) {
        this.beginDate = beginDate;
    }

    public String getEndDate() {
        return endDate;
    }

    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }

    public String getPageNo() {
        return pageNo;
    }

    public void setPageNo(String pageNo) {
        this.pageNo = pageNo;
    }

    public String getHmac() {
        return hmac;
    }

    public void setHmac(String hmac) {
        this.hmac = hmac;
    }

    public static String signature(TradeInfoQueryRequest request) {
        StringBuffer sb = new StringBuffer();
        sb.append(request.getMainCustomerNumber() == null? "":request.getMainCustomerNumber());
        sb.append(request.getCustomerNumber() == null?"":request.getCustomerNumber());
        sb.append(request.getSplitterType()==null?"":request.getSplitterType());
        sb.append(request.getBeginDate() == null?"":request.getBeginDate());
        sb.append(request.getEndDate() == null?"":request.getEndDate());
        sb.append(request.getOrderNo() == null?"":request.getOrderNo());
        sb.append(request.getPageNo() == null?"":request.getPageNo());
        return Digest.hmacSign(sb.toString(), PayConstants.YB_PARAMS_HMAC_KEY);
    }

    public static Part[] builderPart(TradeInfoQueryRequest request) {
        List<Part> parts = new ArrayList<Part>();
        parts.add(new StringPart("mainCustomerNumber",request.getMainCustomerNumber()==null?"":request.getMainCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("customerNumber",request.getCustomerNumber() == null?"":request.getCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("splitterType",request.getSplitterType() == null?"":request.getSplitterType(),"UTF-8"));
        parts.add(new StringPart("orderNo",request.getOrderNo() == null?"":request.getOrderNo(),"UTF-8"));
        parts.add(new StringPart("beginDate",request.getBeginDate() == null?"":request.getBeginDate(),"UTF-8"));
        parts.add(new StringPart("endDate",request.getEndDate() == null?"":request.getEndDate(),"UTF-8"));
        parts.add(new StringPart("pageNo",request.getPageNo() == null?"":request.getPageNo(),"UTF-8"));
        parts.add(new StringPart("hmac",request.getHmac()== null?"":request.getHmac(),"UTF_8"));
        return parts.toArray(new Part[parts.size()]);
    }

}
